import sys


def count_characters(text):

    return len(text)


def count_words(text):

    return len(text.split())


def count_sentences(text):

    sentences = text.split('.')
    sentences = [sentence.strip() for sentence in sentences if sentence.strip()]
    return len(sentences)


def main(file_path, mode):
    try:
        with open(file_path, 'r', encoding='utf-8') as file:
            text = file.read().replace('\n', ' ').replace('\r', ' ')

            if mode == '-c':
                print(f"字符数量: {count_characters(text)}")
            elif mode == '-w':
                print(f"单词数量: {count_words(text)}")
            elif mode == '-s':
                print(f"句子数量: {count_sentences(text)}")
            else:
                print("Invalid mode. Use -c, -w, or -s.")
    except FileNotFoundError:
        print("The file was not found. Please check the file path.")
    except Exception as e:
        print(f"An error occurred: {e}")


if __name__ == "__main__":
    if len(sys.argv) != 3:
        print("Usage: python wc.py [-c|-w|-s] file.txt")
    else:
        mode = sys.argv[1]
        file_path = sys.argv[2]
        main(file_path, mode)